<?php

require_once 'DaoFactoryCreateQuery.php';
require_once APP_ENTITY.DS.'EntityTorneo.php';
require_once APP_ENTITY.DS.'ValueEntity.php';

class DaoTorneo {

 function __construct() {

 }

 public function torneoList() {
        $list = array();

        $entity = new Torneo();
        $dao = new DaoFactory();
        $sqlCreate = new DaoFactoryCreateQuery();
        $sql = $sqlCreate->genericSelect($entity, "tornei");
        $rs = $dao->eseguiQuery($sql);
        
        foreach ( $rs as $row) {
            $torneo = new Torneo();
            $value = new ValueEntity($torneo, $row);
            $torneo = $value->getEntytyValorized();
            array_push($list, $torneo);

        }
        
        return $list;
 }

 function getTorneoById($id) {

        $list = Array();
        $entity = new Torneo();
        $entity->setId($id);
        $dao = new DaoFactory();
        $sqlCreate = new DaoFactoryCreateQuery();
        $sql = $sqlCreate->genericSelect($entity, "tornei");
        $rs = $dao->eseguiQuery($sql);

        foreach ( $rs as $row) {
            $user = new Torneo();
            $value = new ValueEntity($user, $row);
            $user = $value->getEntityValorized();
            if(!empty($user))
                array_push($list, $user);

        }
        if(empty($list))
            $entity = null;
        else
            $entity = $list[0];

        return $entity;
 }

 function getTorneoByNome($nome) {

        $list = Array();
        $entity = new Torneo();
        $entity->setNome($nome);
        $dao = new DaoFactory();
        $sqlCreate = new DaoFactoryCreateQuery();
        $sql = $sqlCreate->genericSelect($entity, "tornei");
        $rs = $dao->eseguiQuery($sql);

        foreach ( $rs as $row) {
            $user = new Torneo();
            $value = new ValueEntity($user, $row);
            $user = $value->getEntityValorized();
            if(!empty($user))
                array_push($list, $user);

        }
        if(empty($list))
            $entity = null;

        return $list;
 }

}

 /*
 $user = new DaoUser();
 var_dump($user->getUserByUsername("admin"));
  */

?>